/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import Control.Point;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;

/**
 *
 * @author Administrator
 */
public class BlockColor extends Shape{
    Point[] ll;
    int n;
    Color color;
    int oldColor;
    public BlockColor( Point[] ll,int n1,Color color ,int oldColor){
        n=n1;
        this.ll=ll;
        this.color=color;
        this.oldColor=oldColor;
    }
    
    public void addPoint(Point point){
        if(n==0)
        {
            n++;
            ll=new Point[n];
            ll[0]=point;
        }
        else
        {
            n++;
            Point[] t=new Point[n];
            for(int i=0;i<n-1;i++)
            {
                t[i]=ll[i];
            }
            t[n-1]=point;
            ll=t;
        }
    }


    @Override
    public void drawShape(Graphics g, BufferedImage a) {
//        WritableRaster wr = a.getRaster();
//                int[] color1= new int[3];
//                color1[0]=color.getRed();
//                color1[1]=color.getGreen();
//                color1[2]=color.getBlue();
//        int color1=color.getRGB();
//        for(int i=0;i<n;i++){
//            wr.setPixel(ll[i].getX(), ll[i].getY(), color1);
//            a.setRGB(ll[i].getX(), ll[i].getY(), color1);
//        }
    }
    
    public void undo(BufferedImage a){
        for(int i=0;i<n;i++){
            a.setRGB(ll[i].getX(), ll[i].getY(), oldColor);
        }
    }
    
    public void redo(BufferedImage a){
         WritableRaster wr = a.getRaster();
                int[] color1= new int[3];
                color1[0]=color.getRed();
                color1[1]=color.getGreen();
                color1[2]=color.getBlue();
        for(int i=0;i<n;i++){
            wr.setPixel(ll[i].getX(), ll[i].getY(), color1);
        }
    }

    @Override
    public void toMove(int x, int y) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    @Override
    public boolean isContain(Point p) {
        return false;
    }
}
